<!DOCTYPE html>
<html lang="zh-cn" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta name="renderer" content="webkit">
    <title></title>
    <link rel="stylesheet" href="css/pintuer.css">
    <link rel="stylesheet" href="css/admin.css">
    <script src="js/jquery.js"></script>
    <script src="js/pintuer.js"></script>
    <script src="/js/vuejs-2.5.16.js"></script>
    <script src="/js/axios-0.18.0.js"></script>
	<script src="/js/laydate/laydate.js"></script>
</head>
<body>
<div class="panel admin-panel" id="papersDiv">
    <div class="panel-head" id="add"><strong><span class="icon-pencil-square-o"></span>增加试卷内容</strong></div>
    <div class="body-content">
        <form method="post" class="form-x">
            <input type="hidden" name="id" v-model="papers.id">
            <div class="form-group">
                <div class="label">
                    <label>问卷名称：</label>
                </div>
                <div class="field">
                    <input type="text" class="input w50" v-model="papers.name" name="name"/>
                    <div class="tips"></div>
                </div>
            </div>


            <div class="form-group">
                <div class="label">
                    <label>问卷封面：</label>
                </div>
                <div class="field">
                    <input type="file" id="url1" name="cover" class="input tips" style="width:25%; float:left;"
                           data-toggle="hover" data-place="right" @change="uploadFile()"/>
                    <div class="tipss">图片尺寸：1300*500</div>
                </div>
            </div>

            <div class="form-group" v-if="papers.cover">
                <div class="label">
                    <label>原封面：</label>
                </div>
                <div class="field">
                    <img v-bind:src="papers.cover" alt="" width="300" height="100" />
                </div>
            </div>
            <div class="clear"></div>


            <div class="form-group">
                <div class="label">
                    <label>问卷水平(初中高)：</label>
                </div>
                <div class="field">
                    <textarea class="input" style="height:250px; border:1px solid #ddd;" v-model="papers.level"
                              name="level"></textarea>
                    <div class="tips"></div>
                </div>
            </div>

            <div class="clear"></div>

            <div class="form-group">
                <div class="label">
                    <label>问卷星级(2-5)：</label>
                </div>
                <div class="field">
                    <input type="text" class="input" v-model="papers.star" name="star"/>
                </div>
            </div>


            <div class="form-group">
                <div class="label">
                    <label></label>
                </div>
                <div class="field">
                    <a class="button bg-main icon-check-square-o" @click="saveOrUpdate()"> 提交</a>
                </div>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript">
    const app = new Vue({
        el: '#papersDiv',
        data: {
            papers: {},
            paperId:''//
        },
        methods: {
            //图片上传
            uploadFile() {
                let formData = new window.FormData();
                formData.append('uploadFile', document.querySelector('input[type=file]').files[0]);
                let options = {  // 设置axios的参数
                    url: "/soul/file/upload",//访问地址
                    data: formData,
                    method: 'post',
                    headers: {
                        'Content-Type': 'multipart/form-data'
                    }
                };
                axios(options).then(resp => {
                    if (resp.data != "") {
                        this.papers.cover = resp.data;//将图片访问地址记录到对象
                    }
                })
            },
            saveOrUpdate(){
                axios.post("/soul/paper/saveOrUpdatePaper?paperId="+this.paperId,
                     this.papers
                ).then(resp=>{
                    if (resp.data) {
                        location.href="/paper_list.html"
                    }else {
                        alert("保存失败")
                    }
                })
            },

            findById(id){
                axios.get("/soul/paper/findPaperById?id="+id).then(resp=>{
                    this.papers=resp.data;
                })
            }
        },
        created() {
            this.paperId=location.search.split("=")[1]
            if (this.paperId){
                this.findById(this.paperId);
            }
        }
    })
</script>

<script>
    lay('#version').html('-v' + laydate.v);
    //执行一个laydate实例
    laydate.render({
        elem: '#showTime' //指定元素
    });
</script>
</body>
</html>